﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace NDK.Frm
{
    public partial class Frm_ClampingJawChart : Form
    {
        public Frm_ClampingJawChart()
        {
            InitializeComponent();
        }

        public Frm_ClampingJawChart(int x)
        {
            InitializeComponent();
        }

        private void Frm_ClampingJawChart_Load(object sender, EventArgs e)
        {
            Frm_Layout();


        }

        private void Frm_Layout()
        {
            ChartArea area = chart_clampingJaw.ChartAreas[0];
            StripLine upperLimit = new StripLine();
            upperLimit.BackColor = Color.Red;
            upperLimit.IntervalOffset = 80;
            upperLimit.StripWidth = 1;
            upperLimit.Text = "上限";
            upperLimit.TextAlignment = StringAlignment.Near;

            area.AxisY.StripLines.Clear();
            area.AxisY.StripLines.Add(upperLimit);
            area.AxisX.MajorGrid.LineColor = Color.Transparent;
            area.AxisY.MajorGrid.LineColor = Color.Transparent;

            area.AxisX.Minimum = 0;
            area.AxisX.Maximum = 2;
            area.AxisX.Interval = 0.1;

            area.AxisY.Minimum = 0;
            area.AxisY.Maximum = 100;
            area.AxisY.Interval = 5;

            Series series = new Series();
            series.ChartType = SeriesChartType.Spline;            // 线宽2个像素
            series.BorderWidth = 2;            // 线的颜色：红色
            series.Color = Color.Blue;            // 图示上的文字
            series.LegendText = "力夹爪力";
            

            List<PointD> pList = new List<PointD>();
            for (int i = 0; i < 10; i++)
            {
                PointD p = new PointD();
                p.X = (i + 1) * 0.1;
                p.Y = 10+(i + 1) * 8;

                pList.Add(p);
            }

            for (int i = 0; i < 10; i++)
            {
                PointD p = new PointD();
                p.X = 1 + (i + 1) * 0.1;
                p.Y = 80 - (i + 1) * 5;
                pList.Add(p);
            }
            foreach (PointD p in pList)
            {
                series.Points.AddXY(p.X, p.Y);
            }

            chart_clampingJaw.Series.Clear();
            chart_clampingJaw.Series.Add(series);
        }
        private void setLimitLine(StripLine sl,double LimitValue,string Text)
        {
            sl.BackColor = Color.Red;
            sl.IntervalOffset = LimitValue;
            sl.Text = Text;
            sl.TextAlignment = StringAlignment.Near;
        }

        private void chart_clampingJaw_Click(object sender, EventArgs e)
        {
            Frm_Layout();
        }
    }

    class PointD
    {
        private double _x;
        private double _y;

        public Double X { get => _x; set => _x = value; }
        public Double Y { get => _y; set => _y = value; }
    }
}
